package com.bite.demospringmvc;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.List;

@RequestMapping("/request")
@RestController
public class HelloController {
    @RequestMapping("/hello")
    public String hello(){
        return "hello springmvc";
    }
    @RequestMapping("/r1")
    public String get(String name){
        return "接收的参数：" + name;
    }

    @RequestMapping("/r2")
    public String get1(Integer age){
        return "接收的参数：" + age;
    }
    @RequestMapping("/r3")
    public String get2(int age){
        return "接收的参数：" + age;
    }
    @RequestMapping("/r4")
    public String get3(String age, String name){
        return "接收的参数：" + name + ", age : " + age;
    }

    @RequestMapping("/r5")
    public String get4(Student student){
        return "接收的参数：" + student;
    }
    @RequestMapping("r6")
    public String get4(@RequestParam("name") String username){
        return "接收的参数：username" + username;
    }
    @RequestMapping("r7")
    public String get5(@RequestParam("name") String username, @RequestParam("age") String userage){
        return "接收的参数：" + username + " age" + userage;
    }
    @RequestMapping("/r8")
    public String get6(@RequestParam(value = "name", required = false) String name){
        return "接收的参数：" + name;
    }

    /*
    传递数组
     */
    @RequestMapping("/r9")
    public String get7(int[] array){
        return Arrays.toString(array);
    }

    /*
    传递集合
     */
    @RequestMapping("/r10")
    public String get8(@RequestParam(value = "list", required = false) List<String> list){
        return "接收的参数"  + list;
    }

    @RequestMapping("/r11")
    public String get9(@RequestBody Student student){
        return "接收的参数" + student;
    }

    @RequestMapping("/r12/{demoid}/{demoname}")
    public String get10(@PathVariable Integer demoid, @PathVariable("demoname") String name){
        return "路径变量： demoid" + demoid + "demoname" + name;
    }

    @RequestMapping("/r13")
    public String get11(@RequestPart("file")MultipartFile file){
        String filename = file.getOriginalFilename();
        return "接收到的文件名称" + filename;
    }
}
